import requests
import time

# 替换为您自己的 clientKey
client_key = "cc9c18d3e263515c2c072b36a7125eecc078618f"

# 创建任务的URL
create_task_url = "https://api.yescaptcha.com/createTask"

# 创建任务的数据
create_task_data = {
    "clientKey": client_key,
    "task": {
        "type": "CloudFlareTaskS2",
        "websiteURL": "https://nowsecure.nl",
        "proxy": "http://JN3wWChA:Dsg7ckfv@45.91.239.47:62930",  # 替换为您的代理
        "waitLoad": False  # 是否等待页面加载完成
    }
}

# 发送创建任务的请求
response = requests.post(create_task_url, json=create_task_data)
create_task_response = response.json()

if create_task_response['errorId'] == 0:
    task_id = create_task_response['taskId']
    print(f"Task created successfully, Task ID: {task_id}")

    # 获取任务结果的URL
    get_task_result_url = "https://api.yescaptcha.com/getTaskResult"

    # 获取任务结果的数据
    get_task_result_data = {
        "clientKey": client_key,
        "taskId": task_id
    }

    # 等待一段时间后获取任务结果
    while True:
        time.sleep(10)  # 等待10秒
        result_response = requests.post(get_task_result_url, json=get_task_result_data)
        task_result_response = result_response.json()

        if task_result_response['errorId'] == 0:
            if task_result_response['status'] == 'ready':
                solution = task_result_response['solution']
                print(f"Task completed successfully, Solution: {solution}")
                break
            else:
                print("Task is still processing, retrying...")
        else:
            print(f"Error occurred: {task_result_response['errorDescription']}")
            break
else:
    print(f"Error occurred while creating task: {create_task_response['errorDescription']}")
